import configparser

# base conversion helper functions
def bin2dec(s):
    return str(int(s, 2))

def oct2dec(s):
    return str(int(s, 8))

def hex2dec(s):
    return str(int(s, 16))

def dec2hex(s):
    return hex(int(s))

def dec2oct(s):
    return oct(int(s))

def dec2bin(s):
    return bin(int(s))

def hex2oct(s):
    return dec2oct(hex2dec(s))

def hex2bin(s):
    return dec2bin(hex2dec(s))

def oct2hex(s):
    return dec2hex(oct2dec(s))

def bin2hex(s):
    return dec2hex(bin2dec(s))

def oct2bin(s):
    return dec2bin(oct2dec(s))

def bin2oct(s):
    return dec2oct(bin2dec(s))

def read_item_from_config_ini(section, item):
    # print(os.system('pwd'))
    # print('==================================')
    cf = configparser.ConfigParser()
    cf.read('./Config.ini', encoding='gbk')
    return cf.get(section, item)

def write_item_to_config_ini(section, item, value):
    cf = configparser.ConfigParser()
    cf.read('./Config.ini', encoding='gbk')
    cf.set(section, item, value)
    with open('./Config.ini', 'w') as configfile:
        cf.write(configfile)
    return 'save to Config.ini, ok.'